﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace calculator
{
    [TestFixture]
    class checkerTest
    {
        [Test]
        public void testConstructor()
        {
            ExpressionParser check = new ExpressionParser("hello");
            Assert.IsInstanceOf(typeof(ExpressionParser), check);
        }

        [Test]
        public void testEmptyOrNull()
        {
            
            try
            {
                ExpressionParser check = new ExpressionParser("");
                Assert.Fail("Empty string exception");
            }
            catch (ArgumentException)
            {
                //The test is a success
            }
        }

        [Test]
        public void testBasicTest()//This tests the rudementary checking of the string, e.g. how many () there are and ileagal characters
        {
            ExpressionParser check = new ExpressionParser("()X and Y");
            Assert.IsTrue(check.basicCheck());
            check.setChecker("X and 9");
            Assert.IsFalse(check.basicCheck());
            check.setChecker("(X and Y");
            Assert.IsFalse(check.basicCheck());
            check.setChecker("(X and Y)");
            Assert.IsTrue(check.basicCheck());
        }

        [Test]
        public void testCheckString()
        {
            ExpressionParser c = new ExpressionParser("X AND Y VOR Z");
            Assert.IsFalse(c.checkString());
            
            c.setChecker("X AND Y AND Y OR Z");
            Assert.IsTrue(c.checkString());

            c.setChecker("(Y AND Y) OR (Y AND Y)");
            Assert.IsTrue(c.checkString());

            c.setChecker("X AND Y OR (Y AND Y)");
            Assert.IsTrue(c.checkString());
            
            c.setChecker("Y AND Y");
            Assert.IsTrue(c.basicCheck());
            
            c.setChecker("(X) AND Y AND Y");
            Assert.IsTrue(c.checkString());
            
            c.setChecker("() AND Y AND Y");
            Assert.IsFalse(c.checkString());
            
            c.setChecker("X AND (X AND Y");
            Assert.IsFalse(c.checkString());

            c.setChecker("X AND Z OR (X AND Z AND Y OR Z)");
            Assert.IsTrue(c.checkString());
        }
    }
}
